<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Sql Azure Query
</asp:Content>
<asp:Content ContentPlaceHolderID="Scripts" ID="scripts" runat="server">

	<script type="text/javascript">
		function SqlExecute() {

			$("#result").html("Working...");
			$("#bExecute").attr("disabled", true);

			jQuery.ajax({
				type: 'GET',
				url: '/Sql/Execute',
				data: { query: $("#query").val(), storageId: $("#storageId").val(), databaseName: $("#DatabaseName").val() },
				success: function(msg) {
					$("#result").html(msg);
					$("#bExecute").attr("disabled", false);
				}
			});
		}
	</script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
	<%= Html.Hidden("storageId", ViewData["storageId"]) %>
	<h2>
		Sql Azure</h2>
	<% if ((bool)ViewData["IsConnectionSuccess"])
		{ %>
	<p>
		Database:
		<%= Html.DropDownList("DatabaseName", (IEnumerable<SelectListItem>)ViewData["Databases"])%></p>
	<p>
		Database:
		<%= Html.Encode(ViewData["Database"])%>; Server Version:
		<%= Html.Encode(ViewData["ServerVersion"])%></p>
	<textarea id="query" cols="100" rows="10"></textarea>
	<br />
	<input id="bExecute" type="button" value="Execute" onclick="SqlExecute()" />
	<br />
	<div id="result">
	</div>
	<%}
		else
		{%>
	<h3>
		Sorry connection was not established.</h3>
	<div class="field-validation-error">
		<%= ViewData["ErrorMessage"] %>
	</div>
	<% }%>
	<p>
		<%= Html.ActionLink("Close", "List", "AzureStorage")%>
	</p>
</asp:Content>